package com.idheima.Stream.StreamApi;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student("小王", 18, 66));

        students.add(new Student("小张", 17, 99));
        students.add(new Student("小李李", 26, 20));
        students.add(new Student("小赵", 16, 77));
        students.add(new Student("小刘刘", 19, 18));
        students.add(new Student("小李", 26, 20));
        //找出所有三个子的学生，并输出数量
        long count = students.stream()
                .filter(student -> student.getName().length() == 3)
                .count();
        System.out.println(count);
        System.out.println("--------------------------------");
        //找出考试最后一名学生的成绩
        Optional<Student> stream = students.stream()
                .min((s1, s2) -> Double.compare(s1.getScore(), s2.getScore()));
        Student student = stream.get();
        System.out.println(student);
        //找出所有成绩不合格的学生，返回学生集合
        List<Student> students1=students.stream()
                .filter(student1 -> student1.getScore() < 60)
                .collect(Collectors.toList());
        System.out.println(students1);

        Set<Student> stream1 = students.stream()
                .filter(student1 -> student1.getScore() < 60)
                .collect(Collectors.toSet());
        System.out.println(stream1);
        System.out.println("--------------------------------");
        Map<String, Double> map =students.stream()
                .filter(s -> s.getScore() < 60)
                .collect(Collectors.toMap(s -> s.getName(), s -> s.getScore()));


    }
}
